import request from './index'

// 获取验证码
export function getCode(phone) {
  return request({
    url: '/user/code',
    method: 'post',
    data: { phone }
  });
}

// 登录
export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data
  });
}

// 注册
export function register(data) {
  return request({
    url: '/user/register',
    method: 'post',
    data
  });
}

// 获取图形验证码
export function getCaptchaImage() {
  return request({
    url: '/user/captcha',
    method: 'get',
    responseType: 'blob',
    withCredentials: true,
    headers: {
      'Accept': 'image/jpeg',
      'Cache-Control': 'no-cache',
      'Pragma': 'no-cache'
    },
    transformRequest: [(data, headers) => {
      // 移除默认的 Content-Type
      delete headers['Content-Type'];
      return data;
    }],
    validateStatus: function (status) {
      return status === 200;
    }
  });
}